package com.we823.cms.repository.service.extension;

import java.util.List;

import com.github.pagehelper.PageInfo;
import com.we823.cms.common.web.pageable.PageRequest;
import com.we823.cms.common.web.pageable.Sort;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.stereotype.Service;

import com.we823.cms.model.extension.CaseCategory;
import com.we823.cms.model.extension.CaseModel;
import com.we823.cms.repository.dao.extension.CaseMapper;
import com.we823.cms.repository.service.AbstractBaseService;
import tk.mybatis.mapper.entity.Example;

@Service("caseService")
public class CaseService extends AbstractBaseService<CaseModel, Integer> {

	private CaseMapper caseMapper;
	@Autowired
	public CaseService(CaseMapper caseMapper) {
		super(caseMapper);
		this.caseMapper = caseMapper;
	}
	public List<CaseModel> findByCategory(CaseCategory caseCategory){
		CaseModel caseModel = new CaseModel();
		caseModel.setCategory(caseCategory);
		return caseMapper.select(caseModel);
	}
	public List<CaseModel> findByCategory(CaseCategory caseCategory, Sort sort) {
		setSortInfo(sort);
		return this.findByCategory(caseCategory);
	}
	public PageInfo<CaseModel> findByCategory(CaseCategory caseCategoryModel, PageRequest pageRequest) {
		setPageInfo(pageRequest);
		return new PageInfo<>(this.findByCategory(caseCategoryModel));
	}
	public List<CaseModel> findByThumbNotNull(){
		Example example = new Example(CaseModel.class);
		Example.Criteria criteria = example.createCriteria();
		criteria.andIsNotNull("thumb");

		return caseMapper.selectByExample(example);
	}
	public List<CaseModel> findByThumbNotNull(Sort sort) {
		setSortInfo(sort);
		return this.findByThumbNotNull();
	}
	public PageInfo<CaseModel> findByThumbNotNull(PageRequest pageRequest) {
		setPageInfo(pageRequest);
		return new PageInfo<>(this.findByThumbNotNull());
	}

	public List<CaseModel> findByCategoryAndThumbNotNull(CaseCategory caseCategoryModel) {
		Example example = new Example(CaseModel.class);
		Example.Criteria criteria = example.createCriteria();
		criteria.andEqualTo("category", caseCategoryModel.getName());
		criteria.andIsNotNull("thumb");
		return caseMapper.selectByExample(example);
	}

	public List<CaseModel> findByCategoryAndThumbNotNull(
			CaseCategory caseCategoryModel, Sort sort) {
		setSortInfo(sort);
		return this.findByCategoryAndThumbNotNull(caseCategoryModel);
	}
	public PageInfo<CaseModel> findByCategoryAndThumbNotNull(
			CaseCategory caseCategoryModel, PageRequest pageRequest) {
		setPageInfo(pageRequest);
		return new PageInfo<>(this.findByCategoryAndThumbNotNull(caseCategoryModel));
	}

	
	
	
}
